package com.ts.modules.movie_session.controller;

import com.ts.common.annotation.LogOperation;
import com.ts.common.constant.Constant;
import com.ts.common.page.PageData;
import com.ts.common.utils.Result;
import com.ts.common.validator.ValidatorUtils;
import com.ts.common.validator.group.AddGroup;
import com.ts.common.validator.group.DefaultGroup;

import com.ts.feign.dto.SessionDTO;
import com.ts.modules.movie_session.service.SessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;


/**
 * 
 *
 * @author Ywl 193363874@qq.com
 * @since 1.0.0 2023-07-15
 */
@RestController
@RequestMapping("/session")
@Api(tags="")
public class SessionController {
    @Autowired
    private SessionService sessionService;

    @GetMapping("/page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    @RequiresPermissions("session:session:page")
    public Result<PageData<SessionDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<SessionDTO> page = sessionService.page(params);

        return new Result<PageData<SessionDTO>>().ok(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("信息")
    @RequiresPermissions("session:session:info")
    public Result<SessionDTO> get(@PathVariable("id") Long id){
        SessionDTO data = sessionService.get(id);

        return new Result<SessionDTO>().ok(data);
    }

    @PostMapping
    @ApiOperation("保存")
    @LogOperation("保存")
    @RequiresPermissions("session:session:save")
    public Result save(@RequestBody SessionDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        sessionService.save(dto);

        return new Result();
    }
}